/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*   File:      SignalAnalysis.cpp
*   Author:    刘洋兵
*   Function:  处理中间通讯发送的协议，并作相应处理
*   Time:      2025-09-09
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "SignalAnalysis.h"

SignalAnalysis::SignalAnalysis(QWidget *parent)
    : QWidget(parent)
{

}


void SignalAnalysis::handleSignal(const QJsonObject &obj)
{
    Json_TableRefresh tableRefresh;
    Json_LssueJudgment lssueJudgment;
    if(MyDatabase::getInstance().openDatabase())
    {
        LOG_ERROR("数据库打开失败,修改数据库配置参数");
        QMessageBox::warning(nullptr, "警告", "数据库打开失败,修改数据库配置参数");
        QSqlDatabase::database().rollback();
        return;
    }
    int code = obj["function_code"].toInt();
    if(code==601)
    {
        tableRefresh.tablename = obj["data_info"].toObject()["table_name"].toString();
        tableRefresh.function_code = obj["function_code"].toInt();
        tableRefresh.request_id = obj["request_id"].toString();
        // 刷新对应表
        MyDatabase::getInstance().refreshTable(tableRefresh.tablename);
    }
    else if (code==602) {
        lssueJudgment.code = obj["data_info"].toObject()["code"].toInt();
        lssueJudgment.info = obj["data_info"].toObject()["info"].toString();
        lssueJudgment.function_code = obj["function_code"].toInt();
        lssueJudgment.request_id = obj["request_id"].toString();
        if(lssueJudgment.code)
        {
            SaveMessage data = CommandSendorReceive::getInstance().getSaveMessage(lssueJudgment.request_id);
            // 刷新对应表
            MyDatabase::getInstance().refreshTable(data.tablename);
            QMessageBox::information(nullptr,
                                     "操作完成",
                                     "数据下发成功!");
        }else {
            LOG_ERROR(lssueJudgment.info);
            QMessageBox::warning(nullptr,
                                 "警告",
                                 "操作失败,请重新下发操作指令!");
        }
    }
}
